import logging
from django.db import connection

cursor = connection.cursor()

from crontab import CronTab
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from rest_framework.authentication import TokenAuthentication
from rest_framework.parsers import JSONParser
from rest_framework.views import APIView

from backend.common.common_db import Interface, UpdataInterface

from backend.common.api_response import JsonResponse
from backend.common.common import record_dynamic
from backend.models import Lyzd_Interface, Lyzd_Interface_Param, Lyzd_Interface_Header, \
    Sys_Project, Sys_Model
# from backend.serializers import ProjectSerializer, ProjectDeserializer, \
#     ProjectMemberDeserializer
from backend.serializers import Sys_InterfaceSerializer, Lyzd_Interface_HeaderSerializer, Lyzd_InterfaceParamSerializer, \
    Lyzd_Interface_HeaderSerializerAddParam, Lyzd_InterfaceParamSerializerAddParam

logger = logging.getLogger(__name__)  # 这里使用 __name__ 动态搜索定义的 logger 配置，这里有一个层次关系的知识点。
"""
龙盈智达环境列表
"""


class LyzdInterfaceList(APIView):
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def get(self, request):
        """
        获取项目列表
        :param request:
        :return:
        """
        try:
            page_size = int(request.GET.get("page_size", 20))
            page = int(request.GET.get("page", 1))

        except (TypeError, ValueError):
            return JsonResponse(code="999985", msg="page and page_size must be integer!")

        interface_name_zh = request.GET.get("interface_name_zh")
        """获取所有project，去掉status=1的project"""
        project = Sys_Project.objects.filter(status=0)
        """获取所有model，去掉status=1的model"""
        model = Sys_Model.objects.filter(status=0)

        if interface_name_zh:
            obi = Lyzd_Interface.objects.filter(interface_name_zh__contains=interface_name_zh, project__in=project,
                                                model__in=model).order_by("delete_flag","-id")

        else:

            obi = Lyzd_Interface.objects.filter(project__in=project, model__in=model).order_by("delete_flag","-id")

        print(obi.count())
        totalCount=obi.count()

        paginator = Paginator(obi, page_size)  # paginator对象
        total = paginator.num_pages  # 总页数

        try:

            obm = paginator.page(page)


        except PageNotAnInteger:

            obm = paginator.page(1)
        except EmptyPage:

            obm = paginator.page(paginator.num_pages)
        serialize = Sys_InterfaceSerializer(obm, many=True)

        # json_data = serializers.serialize("json", obm, ensure_ascii=False)
        return JsonResponse(data={"data": serialize.data,
                                  "page": page,
                                  "total": total,
                                  "totalCount":totalCount,
                                  }, code="999999", msg="成功")


"""
新增interface
"""


class AddIntface(APIView):
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def parameter_check(self, data):

        """
        校验参数
        :param data:
        :return:
        """

        try:
            # 校验必传参数
            if not data["getModelFirstID"] or not data["getProjectFirstID"] or not data["interface_name_zh"] or not \
                    data["interface_name_en"]:
                return JsonResponse(code="999996", msg="参数必填校验失败!")
            # if data["status"] not in [True, False]:
            #     return JsonResponse(code="999996", msg="参数有误!")
            # if not isinstance(data["project_id"], int):
            #     return JsonResponse(code="999996", msg="参数有误!")
            # if data["httpType"] not in ["HTTP", "HTTPS"]:
            #     return JsonResponse(code="999996", msg="参数有误1!")
            if data["requestType"] not in ["POST", "GET", "PUT", "DELETE"]:
                return JsonResponse(code="999996", msg="参数有误2!")
            # if data["requestParameterType"] not in ["form-data", "raw", "Restful"]:
            #     return JsonResponse(code="999996", msg="参数有误!")
        except KeyError:
            return JsonResponse(code="999996", msg="参数有误3!")

    def post(self, request):
        """
        新增接口
        :param request:
        :return:
        """

        data = JSONParser().parse(request)

        result = self.parameter_check(data)

        if result:
            return result

        api_name = Lyzd_Interface.objects.filter(interface_name_zh=data["interface_name_zh"],
                                                 project=data["getProjectFirstID"])

        b = Lyzd_Interface.objects.filter(id=1)

        if len(api_name):

            return JsonResponse(code="999997", msg="同一个项目下存在相同接口名称!")
        else:
            with transaction.atomic():  # 执行错误后，帮助事物回滚

                serialize = Sys_InterfaceSerializer(data=data)

                record_dynamic(project=data["getProjectFirstID"],
                               _type="新增", operationObject="接口", user=request.user.pk,
                               data="新增接口“%s”" % data["interface_name_zh"])

                # 获取加密解密数据
                data["getModelFirstID"]
                ApiHttpType = data["Http"]  # 包含http、https、webservice 供后台使用

                interface_name_zh = data["interface_name_zh"]  # 中文名
                isList = data["isList"]  # 中文名
                interface_name_en = data["interface_name_en"]  # 英文名方法名
                requestType = data['requestType']  # 请求方式post、put等

                authentication = 1  # 加密方式 0不加密1加密;后面有判断
                create_user = str(request.user.username)

                project_id = data["getProjectFirstID"]  # 项目id
                model_id = str(data["getModelFirstID"])  # 模块id

                try:
                    if not data["MiURL"] or not data["JMiURL"]:
                        print("不走加密---------------")
                except:
                    authentication = 0

                try:
                    encryption = data["MiURL"]
                except:
                    encryption = ''
                try:
                    decrypt = data["JMiURL"]
                except:
                    decrypt = ''

                try:
                    listPadding = data["listPadding"]
                except:
                    listPadding = ''

                """空数据处理"""

                try:
                    inParamShow = data["inParamShow"]
                except:
                    inParamShow = ''
                try:
                    outParamShow = data["outParamShow"]
                except:
                    outParamShow = ''
                try:
                    content = data["content"]
                except:
                    content = ''
                # interface_name_zh, interface_name_en, requestType, encryption, decrypt, authentication
                # , create_user, inParamShow, outParamShow, content, project_id, model_id
                """调用增加接口全参接口"""
                Interface.addInterface(interface_name_zh, interface_name_en, requestType,
                                       encryption,
                                       decrypt,
                                       authentication,
                                       create_user,
                                       inParamShow,
                                       outParamShow,
                                       content,
                                       project_id,
                                       model_id,ApiHttpType,isList,listPadding
                                       )

            add_id = Lyzd_Interface.objects.filter(interface_name_zh=data["interface_name_zh"],
                                                   project=data["getProjectFirstID"])

            id_new = add_id[0].id
            """操作lyzd_interface_param表"""
            requestList = data["requestList"]

            for i in requestList:

                """
                param_key入参  
                interface_id 主表id
                relation 是否关联
                relation_interface_id 关联接口id
                
                """
                param_key = i["name"]  # 必填
                try:
                    relation = i["yilai"]
                except:
                    relation = '0'
                try:
                    relation_interface_id = i["_type1"]
                except:
                    relation_interface_id = ''

                try:
                    param_type = i["_type"]
                except:
                    param_type = ''
                try:
                    _type = i["_type"]  # 判断是否是随机数 Random则是随机数，否则不是
                except:
                    _type = ''

                print(_type)
                if _type == "Random":
                    RanType = i["_type3"]
                    RanValue = '1'
                else:
                    RanValue = '0'
                    RanType = ''

                print(RanType)
                try:
                    relation_interface_key = i["key"]
                except:
                    relation_interface_key = ''
                Interface.addInterfaceParam(
                    param_key,  # 入参,
                    param_type,
                    id_new,  # 主表id
                    relation,  # 是否关联
                    relation_interface_id,  # 关联接口id
                    relation_interface_key,  # 追加关键字
                    RanValue,RanType

                )

            # 操作Lyzd_Interface_Header表
            headerDictList = data["headerDict"]
            for j in headerDictList:

                header_key = j["name"]  # 必填
                try:
                    header_key_value = j["header_key_value"]  # 当选择webservice时是非必填
                except:
                    header_key_value = '' # 当选择webservice时是非必填,可以为空
                try:
                    relation = j["yilai"]
                except:
                    relation = '0'
                try:
                    relation_interface_id = j["_type1"]
                except:
                    relation_interface_id = ""

                try:
                    param_type = j["_type"]
                except:
                    param_type = ''
                try:
                    relation_interface_key = j["key"]
                except:
                    relation_interface_key = ""
                    # UpdateInterfaceHeader2

                Interface.addInterfaceHeader(
                    header_key,  # 入参,
                    header_key_value,
                    param_type,
                    id_new,  # 主表id
                    relation,  # 是否关联
                    relation_interface_id,  # 关联接口id
                    relation_interface_key

                )

            """非通用追加一条数据到header表"""
            header = Lyzd_Interface_Header(interface_id=id_new, header_key_value=data['ContentType'],
                                           header_key="Content-Type", param_type="String")
            header.save()

            return JsonResponse(code="999999", msg="成功!")


class CopyIntface(APIView):
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def parameter_check(self, data):

        """
        校验参数
        :param data:
        :return:
        """

        try:
            # 校验必传参数
            if not data["getModelFirstID"] or not data["getProjectFirstID"] or not data["interface_name_zh"] or not \
                    data["interface_name_en"] or not data["cid"]:
                print(data["getModelFirstID"], data["getProjectFirstID"], data["interface_name_zh"], \
                      data["interface_name_en"], data["cid"])
                return JsonResponse(code="999996", msg="参数必填校验失败!")

        except KeyError:
            return JsonResponse(code="999996", msg="参数不全!")

    def post(self, request):
        """
        新增接口
        :param request:
        :return:
        """

        data = JSONParser().parse(request)

        result = self.parameter_check(data)

        if result:
            return result

        api_name = Lyzd_Interface.objects.filter(interface_name_zh=data["interface_name_zh"],
                                                 project=data["getProjectFirstID"])

        b = Lyzd_Interface.objects.filter(id=1)

        if len(api_name):

            return JsonResponse(code="999997", msg="同一个项目下存在相同接口名称!")
        else:
            with transaction.atomic():  # 执行错误后，帮助事物回滚

                serialize = Sys_InterfaceSerializer(data=data)

                record_dynamic(project=data["getProjectFirstID"],
                               _type="新增", operationObject="接口", user=request.user.pk,
                               data="新增接口“%s”" % data["interface_name_zh"])

                # 获取加密解密数据
                data["getModelFirstID"]
                ApiHttpType = data["Http"]  # 包含http、https、webservice 供后台使用

                interface_name_zh = data["interface_name_zh"]  # 中文名
                isList = data["isList"]  # 中文名
                interface_name_en = data["interface_name_en"]  # 英文名方法名
                try:
                    requestType = data['requestType']  # 请求方式post、put等
                except:
                    requestType="POST"


                authentication = 1  # 加密方式 0不加密1加密;后面有判断
                create_user = str(request.user.username)

                project_id = data["getProjectFirstID"]  # 项目id
                model_id = str(data["getModelFirstID"])  # 模块id

                try:
                    if not data["MiURL"] or not data["JMiURL"]:
                        print("不走加密---------------")
                except:
                    authentication = 0

                try:
                    encryption = data["MiURL"]
                except:
                    encryption = ''
                try:
                    decrypt = data["JMiURL"]
                except:
                    decrypt = ''

                try:
                    listPadding = data["listPadding"]
                except:
                    listPadding = ''

                """空数据处理"""

                try:
                    inParamShow = data["inParamShow"]
                except:
                    inParamShow = ''
                try:
                    outParamShow = data["outParamShow"]
                except:
                    outParamShow = ''
                try:
                    content = data["content"]
                except:
                    content = ''
                # interface_name_zh, interface_name_en, requestType, encryption, decrypt, authentication
                # , create_user, inParamShow, outParamShow, content, project_id, model_id
                """调用增加接口全参接口"""
                Interface.addInterface(interface_name_zh, interface_name_en, requestType,
                                       encryption,
                                       decrypt,
                                       authentication,
                                       create_user,
                                       inParamShow,
                                       outParamShow,
                                       content,
                                       project_id,
                                       model_id, ApiHttpType, isList, listPadding
                                       )

            add_id = Lyzd_Interface.objects.filter(interface_name_zh=data["interface_name_zh"],
                                                   project=data["getProjectFirstID"])

            id_new = add_id[0].id
            """操作lyzd_interface_param表"""
            requestList = data["requestList"]

            for i in requestList:

                """
                param_key入参  
                interface_id 主表id
                relation 是否关联
                relation_interface_id 关联接口id

                """
                param_key = i["param_key"]  # 必填
                try:
                    relation = i["relation"]
                except:
                    relation = '0'
                try:
                    relation_interface_id = i["relation_interface_id"]
                except:
                    relation_interface_id = ''

                try:
                    param_type = i["param_type"]
                except:
                    param_type = ''
                try:
                    _type = i["_type"]  # 判断是否是随机数 Random则是随机数，否则不是
                except:
                    _type = ''

                print(_type)
                if _type == "Random":
                    RanType = i["_type3"]
                    RanValue = '1'
                else:
                    RanValue = '0'
                    RanType = ''

                print(RanType)
                try:
                    relation_interface_key = i["relation_interface_key"]
                except:
                    relation_interface_key = ''
                Interface.addInterfaceParam(
                    param_key,  # 入参,
                    param_type,
                    id_new,  # 主表id
                    relation,  # 是否关联
                    relation_interface_id,  # 关联接口id
                    relation_interface_key,  # 追加关键字
                    RanValue, RanType

                )

            # 操作Lyzd_Interface_Header表
            headerDictList = data["headerDict"]
            for j in headerDictList:

                header_key = j["header_key"]  # 必填
                try:
                    header_key_value = j["header_key_value"]  # 当选择webservice时是非必填
                except:
                    header_key_value = ''  # 当选择webservice时是非必填,可以为空
                try:
                    relation = j["relation"]
                except:
                    relation = '0'
                try:
                    relation_interface_id = j["relation_interface_id"]
                except:
                    relation_interface_id = ""

                try:
                    param_type = j["param_type"]
                except:
                    param_type = ''
                try:
                    relation_interface_key = j["relation_interface_key"]
                except:
                    relation_interface_key = ""
                    # UpdateInterfaceHeader2

                Interface.addInterfaceHeader(
                    header_key,  # 入参,
                    header_key_value,
                    param_type,
                    id_new,  # 主表id
                    relation,  # 是否关联
                    relation_interface_id,  # 关联接口id
                    relation_interface_key

                )

            """非通用追加一条数据到header表"""
            header = Lyzd_Interface_Header(interface_id=id_new, header_key_value=data['ContentType'],
                                           header_key="Content-Type", param_type="String")
            header.save()

            return JsonResponse(code="999999", msg="成功!")

"""edit interface by gaojingyu"""


class EditIntface(APIView):#编辑
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def parameter_check(self, data):

        """
        校验参数
        :param data:
        :return:
        """

        try:
            # 校验必传参数
            if not data["getModelFirstID"] or not data["getProjectFirstID"] or not data["interface_name_zh"] or not \
                    data["interface_name_en"] or not data["cid"]:
                print(data["getModelFirstID"] , data["getProjectFirstID"] , data["interface_name_zh"] , \
                    data["interface_name_en"] , data["cid"])
                return JsonResponse(code="999996", msg="参数必填校验失败!")

        except KeyError:
            return JsonResponse(code="999996", msg="参数不全!")

    def post(self, request):
        """
        新增接口
        :param request:
        :return:
        """

        data = JSONParser().parse(request)

        result = self.parameter_check(data)

        if result:
            return result
        with transaction.atomic():  # 执行错误后，帮助事物回滚

            serialize = Sys_InterfaceSerializer(data=data)

            data["getModelFirstID"]
            ApiHttpType= data["Http"]  # 包含http、https、webservice 供后台使用

            interface_name_zh = data["interface_name_zh"]  # 中文名
            interface_name_en = data["interface_name_en"]  # 英文名方法名
            isList = data["isList"]  # 英文名方法名
            # requestType = data['requestType']  # 请求方式post、put等

            authentication = 1  # 加密方式 0不加密1加密;后面有判断
            create_user = str(request.user.username)

            project_id = data["getProjectFirstID"]  # 项目id
            model_id = str(data["getModelFirstID"])  # 模块id

            try:
                if not data["MiURL"] or not data["JMiURL"]:
                    print("不走加密---------------")
            except:
                authentication = 0

            try:
                encryption = data["MiURL"]
            except:
                encryption = ''
            try:
                decrypt = data["JMiURL"]
            except:
                decrypt = ''

            try :
                listPadding=data["listPadding"]
            except:
                listPadding=''

            """空数据处理"""

            try:
                inParamShow = data["inParamShow"]
            except:
                inParamShow = ''
            try:
                outParamShow = data["outParamShow"]
            except:
                outParamShow = ''
            try:
                content = data["content"]
            except:
                content = ''

            interface_id = data['cid']
            # request_type = data['httpType']
            in_param_show = data['inParamShow']
            out_param_show = data['outParamShow']
            model = data['getModelFirstID']

            UpdataInterface.UpdateInterface3(interface_name_zh, interface_id, interface_name_en,
            # request_type,
                                             authentication, encryption,
                                             decrypt, in_param_show, out_param_show, content,
                                             model,ApiHttpType,isList,listPadding)
            # print(interface_name_zh, interface_id, interface_name_en, request_type, authentication, encryption,
            #       decrypt, in_param_show, out_param_show, content,
            #       model)

            # print("主表更新完成")

        # add_id = Lyzd_Interface.objects.filter(interface_name_zh=data["interface_name_zh"],
        #                                        project=data["getProjectFirstID"])
        #
        # id_new = add_id[0].id
        """操作lyzd_interface_param表"""
        requestList = data["requestList"]
        Lyzd_Interface_Param.objects.filter(interface_id=interface_id).delete()
        print(interface_id)

        for i in requestList:

            """
            param_key入参  
            interface_id 主表id
            relation 是否关联
            relation_interface_id 关联接口id

            """
            param_key = i["param_key"]  # 必填
            try:
                relation = i["relation"]
            except:
                relation = '0'
            try:
                relation_interface_id = i["relation_interface_id"]
            except:
                relation_interface_id = ''
            try:
                relation_interface_id_name = i["relation_interface_id_name"]
            except:
                relation_interface_id_name = ''


            try:
                param_type = i["param_type"]
            except:
                param_type = ''
            # try:
            #     _type = i["_type"]#判断是否是随机数 Random则是随机数，否则不是
            # except:
            #     _type = ''

            # print(_type)
            if param_type=="Random":
                random_number_type=i["random_number_type"]
                random_number='1'
            else:
                random_number = '0'
                random_number_type = ''


            try:
                relation_interface_key = i["relation_interface_key"]
            except:
                relation_interface_key = ''
                # def addInterfaceParam(param_key, param_type, interface_id, relation, relation_interface_id, relation_interface_key):
            # print("关联接口操作")
            # print(relation_interface_id)
            # print(relation_interface_id_name)

            if relation_interface_id is None or relation_interface_id == '':
                if relation_interface_id_name is None or relation_interface_id_name == '':
                    print("不存关联接口")
                    print(relation_interface_id_name)

                elif relation_interface_id_name is not None:  # 首次勾选
                    relation_interface_id = relation_interface_id_name
            elif relation_interface_id is not None:  # 有2种情况 1未操作 2修改均一扫判断接口表，确定传参
                if relation_interface_id_name is None or relation_interface_id_name == '':
                    print("未知错误")
                elif relation_interface_id_name is not None:
                    api_name = Lyzd_Interface.objects.filter(id=relation_interface_id,
                                                             interface_name_zh=relation_interface_id_name)
                    if len(api_name):
                        relation_interface_id = relation_interface_id  # 不修改时
                    else:  # 修改后relation_interface_id和relation_interface_id_name 传到了后台已relation_interface_id为准
                        relation_interface_id = relation_interface_id_name
            # 删除后新增
            # RanValue = '0'    random_number = '0'
            #                 random_number_type = ''
            # RanType
            print("""""""""""""""""""""""""")
            print(random_number)
            print(random_number_type)
            Interface.addInterfaceParam(param_key, param_type, interface_id, relation, relation_interface_id,
                                        relation_interface_key,random_number,random_number_type)

            """接口新增关联表--lyzd_interface_param
            UpdateInterface2
            """

        # 操作Lyzd_Interface_Header表
        headerDictList = data["headerDict"]
        Lyzd_Interface_Header.objects.filter(interface_id=interface_id).delete()
        # print(interface_id)

        for j in headerDictList:
            try:

                header_key = j["header_key"]  # 必填
                header_key_value = j["header_key_value"]  # 必填
            except:
                return JsonResponse(code="999996", msg="请求header异常,Key或者Value参数不全")

            try:
                relation = j["relation"]
            except:
                relation = '0'  # 默认传0 不走关联接口
            try:
                relation_interface_id = j["relation_interface_id"]
            except:
                relation_interface_id = ""
            try:
                relation_interface_id_name = j["relation_interface_id_name"]
            except:
                relation_interface_id_name = ""

            try:
                param_type = j["param_type"]
            except:
                param_type = ''
            try:
                relation_interface_key = j["relation_interface_key"]
            except:
                relation_interface_key = ""

            # print("关联接口操作")
            # print(relation_interface_id)
            # print(relation_interface_id_name)

            if relation_interface_id is None or relation_interface_id == '':
                if relation_interface_id_name is None or relation_interface_id_name == '':
                    print("不存关联接口")
                    print(relation_interface_id_name)

                elif relation_interface_id_name is not None:  #首次勾选
                    relation_interface_id=relation_interface_id_name
            elif  relation_interface_id is not None:#有2种情况 1未操作 2修改均一扫判断接口表，确定传参
                if relation_interface_id_name is None or relation_interface_id_name == '':
                    print("未知错误")
                elif relation_interface_id_name is not None:
                    api_name = Lyzd_Interface.objects.filter(id=relation_interface_id ,interface_name_zh=relation_interface_id_name)
                    if len(api_name):
                        relation_interface_id=relation_interface_id  #不修改时
                    else:# 修改后relation_interface_id和relation_interface_id_name 传到了后台已relation_interface_id为准
                        relation_interface_id = relation_interface_id_name

            #
            # print("header_keybibianli" + header_key)
            # print("关联接口操作处理后")
            # print(relation_interface_id)
            # print(relation_interface_id_name)




            # (param_key, interface_id, param_type, relation, relation_interface_id,
            #  relation_interface_key):

            # print(relation_interface_key)

            UpdataInterface.UpdateInterfaceHeader2(
                header_key, header_key_value, param_type, interface_id, relation, relation_interface_id,
                relation_interface_key)

        """非通用追加一条数据到header表"""
        header = Lyzd_Interface_Header(interface_id=interface_id, header_key_value=data['ContentType'],
                                       header_key="Content-Type", param_type="String")
        header.save()

        return JsonResponse(code="999999", msg="成功!")



class EditStatusApi(APIView):
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def post(self, request):

        """查询条件"""
        # 必传参数
        data = JSONParser().parse(request)

        api_id = tuple(data.values())[0]

        status = Lyzd_Interface.objects.filter(id=api_id)

        flag = status[0].delete_flag

        if flag == '0':
            Lyzd_Interface.objects.filter(id=api_id).update(
                delete_flag=1
            )
            return JsonResponse(code="999999", msg="禁用成功")
        elif flag == '1':
            Lyzd_Interface.objects.filter(id=api_id).update(
                delete_flag=0
            )
            return JsonResponse(code="999999", msg="启用成功")


class ApiEdit(APIView):#获取数据
    authentication_classes = (TokenAuthentication,)
    permission_classes = ()

    def get(self, request):
        # print("?????????")
        # project_id = request.GET.get("project_id")
        """
        获取接口详细信息
        :param request:
        :return:
        """
        # print(request.GET)
        cid = request.GET.get("api_id")
        # print(cid)

        try:

            obm = Lyzd_Interface.objects.filter(id=cid)
            # print(obm
            #       )
            serializer = Sys_InterfaceSerializer(obm, many=True)
            # serialize = Sys_InterfaceSerializer(obm, many=True)
            # print(serializer.data)

            obm1 = Lyzd_Interface_Header.objects.filter(interface=cid).extra(select={
                'relation_interface_id_name': 'SELECT lyzd_interface.interface_name_zh'
                                              ' FROM lyzd_interface WHERE '
                                              'lyzd_interface.id = Lyzd_Interface_Header.relation_interface_id'}
            )

            # print(obm1)

            serializer1 = Lyzd_Interface_HeaderSerializerAddParam(obm1, many=True)

            obm2 = Lyzd_Interface_Param.objects.filter(interface=cid).extra(select={
                'relation_interface_id_name': 'SELECT lyzd_interface.interface_name_zh FROM lyzd_interface WHERE lyzd_interface.id = Lyzd_Interface_Param.relation_interface_id'}
            )
            serializer2 = Lyzd_InterfaceParamSerializerAddParam(obm2, many=True)

            dataAll = {'interface': serializer.data,
                       'header': serializer1.data,
                       'param': serializer2.data}


            # print(dataAll)







        except ObjectDoesNotExist:
            pass
        return JsonResponse(data={'interface': serializer.data,
                                  'header': serializer1.data,
                                  'param': serializer2.data}, code="999999", msg="成功！")
